package com.casi.project.portal.service.impl;

import com.casi.project.portal.domain.MobileHomeMenu;
import com.casi.project.portal.domain.MobileHomeMenuDetails;
import com.casi.project.portal.mapper.IndexApiMapper;
import com.casi.project.portal.service.IndexApiService;
import com.casi.project.portal.vo.IndexApiVO;
import com.casi.project.portal.vo.IndexMobliVO;
import com.casi.project.portal.vo.NoticeVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Auther shp
 * @data2020/4/1510:34
 * @description
 */

@Service
@Transactional(rollbackFor = Exception.class)
public class IndexApiServiceImpl implements IndexApiService{

    @Resource
    private IndexApiMapper mapper;


    @Override
    public List<IndexMobliVO> getAllMenu() {

        List<IndexMobliVO> list=new ArrayList<>();
        IndexMobliVO indexMobliVO ;
        List<IndexApiVO> arrs;
        IndexApiVO indexApiVO;

        List<MobileHomeMenu> homeMenu = mapper.findHomeMenu();
        List<MobileHomeMenuDetails> mobileHomeMenuDetails = mapper.findMobileHomeMenuDetails();

        for (MobileHomeMenu menu : homeMenu) {

            arrs=new ArrayList<>();

            indexMobliVO = new IndexMobliVO();
            indexMobliVO.setPid(menu.getId());
            indexMobliVO.setMenuName(menu.getMenuName());


            for (MobileHomeMenuDetails mobileHomeMenuDetail : mobileHomeMenuDetails) {
                if(mobileHomeMenuDetail.getButtonParentId()==menu.getId()){
                    indexApiVO=new IndexApiVO();
                    indexApiVO.setMenuButtonName(mobileHomeMenuDetail.getMenuButtonName());
                    indexApiVO.setId(mobileHomeMenuDetail.getId());
                    indexApiVO.setMenuButtonIcon(mobileHomeMenuDetail.getMenuButtonIcon());
                    indexApiVO.setMenuButtonUrl(mobileHomeMenuDetail.getMenuButtonUrl());

                    arrs.add(indexApiVO);
                }
            }

            if(menu.getMenuName()!=null && !menu.getMenuName().equals("")){
                indexMobliVO.setArrs(arrs);
                list.add(indexMobliVO);
            }

        }

        return list;
    }

    @Override
    public List<NoticeVO> findNotice() {
        return mapper.findNotice();
    }
}
